<template>
  <ContentWrap>
    <el-descriptions :column="1" border>
      <el-descriptions-item label="发票编号">
        {{ detailData.code }}
      </el-descriptions-item>
      <el-descriptions-item label="开票内容">
        {{ detailData.content }}
      </el-descriptions-item>
      <el-descriptions-item label="客户名称">
        {{ detailData.customerName }}
      </el-descriptions-item>
      <el-descriptions-item label="合同名称">
        {{ detailData.contractName }}
      </el-descriptions-item>
      <el-descriptions-item label="开票金额">
        {{ detailData.receiptAmount }}
      </el-descriptions-item>
      <el-descriptions-item label="开票日期">
        {{ formatDate(detailData.receiptDate, 'YYYY-MM-DD') }}
      </el-descriptions-item>
      <el-descriptions-item label="开票类型">
        <dict-tag :type="DICT_TYPE.CRM_RECEIPT_TYPE" :value="detailData.receiptType" />
      </el-descriptions-item>
      <el-descriptions-item label="开票状态">
        <dict-tag :type="DICT_TYPE.CRM_RECEIPT_STATUS" :value="detailData.status" />
      </el-descriptions-item>
      <el-descriptions-item label="发票抬头">
        {{ receiptTitleData.title }}
      </el-descriptions-item>
      <el-descriptions-item label="备注">
        {{ detailData.remark }}
      </el-descriptions-item>
    </el-descriptions>
  </ContentWrap>
</template>
<script lang="ts" setup>
import { DICT_TYPE } from '@/utils/dict'
import { formatDate } from '@/utils/formatTime'
import { propTypes } from '@/utils/propTypes'
import { ReceiptApi, Receipt } from '@/api/crm/receipt'
import { ReceiptTitleApi, ReceiptTitle } from '@/api/crm/receipttitle'

defineOptions({ name: 'BpmOALeaveDetail' })

const { query } = useRoute() // 查询参数

const props = defineProps({
  id: propTypes.number.def(undefined)
})
const detailLoading = ref(false) // 表单的加载中
const detailData = ref<any>({}) // 详情数据
const receiptTitleData = ref<any>({})
const queryId = query.id as unknown as number // 从 URL 传递过来的 id 编号

/** 获得数据 */
const getInfo = async () => {
  detailLoading.value = true
  try {
    detailData.value = await ReceiptApi.getReceipt(props.id || queryId)
    if (detailData.value != undefined) {
      receiptTitleData.value = await ReceiptTitleApi.getReceiptTitle(detailData.value.titleId)
    }
  } finally {
    detailLoading.value = false
  }
}
defineExpose({ open: getInfo }) // 提供 open 方法，用于打开弹窗

/** 初始化 **/
onMounted(() => {
  getInfo()
})
</script>
